/*
 * @Author: zhang zhijiang 2824735304@qq.com
 * @Date: 2025-03-19 21:14:47
 * @LastEditors: zhang zhijiang 2824735304@qq.com
 * @LastEditTime: 2025-03-19 21:45:34
 * @FilePath: /linux/test_3_19/mythread.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include<iostream>
#include<unistd.h>
#include<cstring>
#include<pthread.h>
using namespace std;

class response
{
public:
    response(int right,int result)
    :_right(right),_result(result)
    {}
    public:
    int _right;
    int _result;
};
class count
{
    public:
    count(int begin,int end,const string & threadname)
    :_begin(begin),_end(end),_threadname(threadname)
    {

    }
public:
    int _begin;
    int _end;
    string _threadname;
};

void* sumcount(void * argvs)
{
    count* cu = static_cast<count*> (argvs);
    response* res = new response(0,0);
    for(int i = cu->_begin;i<=cu->_end;i++)
    {
        res->_result+=i;
    }
    return res;

}
int main()
{
    pthread_t tid;
    count* cu= new count(1,100,"thread 1");
    pthread_create(&tid,nullptr,sumcount,cu);
    void *res;
    pthread_join(tid,&res);
    response* ret= static_cast<response*> (res);
    cout<<ret->_result<<endl;
    return 0;
}
// void* routine(void* argvs)
// {
//     int cnt = 5;
//     while(cnt--)
//     {
//         cout<< pthread_self()<<endl;
//         sleep(1);
//     }
//     return (void*)1;
// }
// int main()
// {
//     pthread_t tid;
//     pthread_create(&tid,nullptr,routine,nullptr);
//     void * ret;
//     pthread_join(tid,&ret);
//     ret = (int*) ret;
//     cout<<ret<<endl;
//     return 0;
// }